﻿#pragma once

#include "common.h"
#include "ui/menu_items.h"
#include "ui/control_base.h"

namespace anip
{
	namespace ui
	{
		class Button;
		class Slider;
		class Joystick;
		class RadioBar;
		class FoldablePanel;
		class TextField;
		
		class FlowHelper
		{
		private:
			class _BeginRow : public WithText<Control>
			{
			public:
				void paint() override;
				void flow(Flow& f) override;
			};

			class _EndRow : public Control
			{
			public:
				void paint() override {};
				void flow(Flow& f) override;
			};

		public:
			FlowHelper() = delete;

			static Control* beginRow(Container& p, const wstring& text);
			static Control* endRow(Container& p);

			static Label* label(Container& p, const wstring& text);
			static Button* button(Container& p, const wstring& text);
			static Slider* slider(Container& p, float min, float max, float val);
			static Joystick* joystick(Container& p);
			static TextField* textField(Container& p, const wstring& text);

			static RadioBar* radioBar(Container& p, int n, const wstring* items);
			static FoldablePanel* foldablePanel(Container& p, const wstring& text);

		};

		class MenuHelper
		{
		public:
			MenuHelper() = delete;

			static Menu& globalMenu(invec2 pos);

			static MenuBar::Item& barButton(MenuBar& m, const wstring& text,
				const std::function<void(MenuBar::Item& self)>& onclick =
					std::function<void(MenuBar::Item&)>());

			static MenuBar::Item& barDropdown(MenuBar& m, const wstring& text,
				const std::function<Menu* (MenuBar::Item& self)>& sub =
					std::function<Menu* (MenuBar::Item& self)>());

			static MenuTextItem& button(Menu& m, const wstring& text,
				const std::function<void(MenuTextItem& self)>& onclick =
					std::function<void(MenuTextItem&)>());

			static MenuTextItem& checkable(Menu& m, const wstring& text, bool checked = false,
				const std::function<void(MenuTextItem& self)>& onclick =
					std::function<void(MenuTextItem&)>());

			static MenuTextItem& subMenu(Menu& m, const wstring& text,
				const std::function<Menu* (MenuTextItem& self)>& sub =
					std::function<Menu* (MenuTextItem& self)>());

			static MenuSeparatorItem& separator(Menu& m);

			static MenuLabelItem& text(Menu& m, const wstring& text);

			static MenuLabelItem& groupHeader(Menu& m, const wstring& text);

			static MenuRadioBarItem& radioBar(Menu& m, bool multi = false, bool none = false);

			static MenuRadioBarItem& buttonBar(Menu& m);

			static MenuRadioBarSubItem& radioItem(
				MenuRadioBarItem& bar,
				const wstring& text,
				const std::function<void(MenuRadioBarSubItem& self)>& onclick =
					std::function<void(MenuRadioBarSubItem&)>());
		};

		class NonIntrusiveDialog
		{
		private:
			struct Btn
			{
				wstring text;
				std::function<void()> click;
			};
			std::vector<Btn> _btns;
			wstring _text;

		public:
			NonIntrusiveDialog(const wstring& t) : _text(t) {}
			NonIntrusiveDialog(NonIntrusiveDialog&) = delete; // ANIP_TODO: shouldn't have this

			NonIntrusiveDialog& addButton(
				const wstring& text, 
				const std::function<void()>& click)
			{
				_btns.push_back({ text, click });
				return *this;
			}

			void show(Control& cont);
		};
	}
}